package dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import entity.NewTime;
import util.db.DBhelp;
import util.db.RowMapper;

public class NewTimeDao {

	private DBhelp<NewTime> dBhelp = new DBhelp<NewTime>();
	
	
	private class NewTimeRowMapper implements RowMapper<NewTime>{

		public NewTime mapRow(ResultSet resultSet) throws SQLException {
			NewTime newTime = new NewTime();
			newTime.setId(resultSet.getString("id"));
			newTime.setLastclickattime(resultSet.getString("lastclickattime"));
			newTime.setLastclickcommenttime(resultSet.getString("lastclickcommenttime"));
			newTime.setProjectid(resultSet.getString("projectid"));
			newTime.setUserid(resultSet.getString("userid"));
			return newTime;
		}
		
	}


	public NewTime findNewtimeByUseridAndProjectid(String userid,
			String projectid) {
		String sql = "select * from t_newtime where userid=? and projectid=?";
		return dBhelp.executeQueryToObject(sql, new NewTimeRowMapper(), userid,projectid);
	}


	public void save(NewTime newTime) {
		String sql = "insert into t_newtime (id,projectid,userid)values(?,?,?)";
		dBhelp.update(sql, newTime.getId(),newTime.getProjectid(),newTime.getUserid());
	}


	public void update(NewTime newTime) {
		String sql = "update t_newtime set lastclickcommenttime=?,lastclickattime=? where projectid=? and userid=?";
		dBhelp.update(sql, newTime.getLastclickcommenttime(),newTime.getLastclickattime(),newTime.getProjectid(),newTime.getUserid());
		
	}
}
